<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class docket_model extends CI_Model
{
	
	public function __construct()
	{
		parent::__construct();

	}
	
	
	public function get_docket($id)
	{ 
	$this->db->select('dispatch.docket_no');
	$this->db->from('dispatch', 'case' );
	$this->db->join('case', 'case.id= dispatch.case_id '  );
	$this->db->where('case.hp_case',$id);
	$q = $this->db->get();
	
	return $q;
		
	}
	
public function get_case_id($id)
{
$this->db->select('case.id');
	$this->db->from('case' );
	$this->db->where('case.hp_case',$id);
	$q = $this->db->get();
	return $q;
	}
public function get_service_id($id)
{
$this->db->select('service_id');
	$this->db->from('case' );
	$this->db->where('case.hp_case',$id);
	$q = $this->db->get();
	return $q;
	}	
public function received_docket($insert)
{ 

$this->db->insert('docket_received',$insert);

}
public function get_disp_view()
	{
	$this->datatables
			->select("docket_received.id as id,case.case_no,docket_received.docket_no,docket_received.received_date,customer.customer_name,customer.mobile")
			->from('customer','case','docket_received')	
			->join('case','customer.service_id=case.service_id')
			->join('docket_received','docket_received.case_id=case.id')
			//->where('diagnosis.status_id',4)
			->add_column("Actions",
			"<center>			<a href='index.php/admin/docket/assigned_engineer/$1'>
								<i class='icon-edit'></i>
								</a>
								
								</center>", "id")
			
			;
	   return  $this->datatables->generate();
	}
	
	public function get_notassigned_view()
	{
	$this->datatables
			->select("docket_received.id as id,case.case_no,case.hp_case,docket_received.docket_no,docket_received.received_date,customer.customer_name,customer.mobile")
			->from('customer','case','docket_received','diagnosis')	
			->join('case','customer.service_id=case.service_id')
			->join('diagnosis','case.id=diagnosis.case_id')
			->join('docket_received','docket_received.case_id=case.id')
			->where('diagnosis.status_id',4)
			->add_column("Actions",
			"<center>			<a href='index.php/admin/docket/assigned_engineer/$1'>
								<i class='icon-edit'></i>
								</a>
								
								</center>", "id")
			
			;
	   return  $this->datatables->generate();
	}
	public function update_status($id)
	{
	
	$insert=array('status_id'=>4,);
	$this->db->update('diagnosis',$insert,array('service_id'=>$id));
	
	}
	public function update_case_status($id)
	{
	
	$insert=array('status_id'=>4,);
	$this->db->update('case',$insert,array('service_id'=>$id));
	
	}
	
	public function get_engineer()
	{
	$this->db->select('users.*');
	$this->db->from('users', 'users_groups' );
	$this->db->join('users_groups', 'users.id= users_groups.user_id   '  );
	$this->db->where('users_groups.group_id',2);
	$q = $this->db->get();
		if($q->num_rows() > 0) {
			foreach (($q->result()) as $row) {
				$data[] = $row;
			}
			return $data;
			
		}
	
	
	
	}	
	
public function get_case_no($id)	
	{
	$this->db->select('case_no,case_id,docket_no');
	$this->db->from('docket_received' );
	$this->db->where('docket_received.id',$id);
	$q = $this->db->get();
	return $q;
	
	
	}
public function get_assign_details($id)
{
$this->db->select('case.case_no,repair.docket_no,repair.assigned_date,repair.expected_date,users.username');
	$this->db->from('case','docket_received','repair','users' );
	$this->db->join('docket_received','case.id=docket_received.case_id');
	$this->db->join('repair','repair.case_id=case.id');
	$this->db->join('users','repair.engineer_id=users.id');
	$this->db->where('docket_received.id',$id);
	$q = $this->db->get();
	return $q;

}	
	
	
	
	
	
	
	}